home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d15 / mewin.arc / CTAGS.CMD < prev    next >
OS/2 REXX Batch file  |  1991-03-12  |  9KB  |  278 lines

  1. ; ctags.cmd,    for MicroEmacs (c) Daniel Lawrence
  2. ;
  3. ; 01 Jun 89 S.D. Maley        No longer compatible w/ versions of MicroEmacs
  4. ;            prior to 3.10 .
  5. ;                Added next-tag, because a tag may occur more
  6. ;            than once in the tags file (Could NOT macro-to-key
  7. ;            next-tag M-FN^V).
  8. ;                Added locality preference, so that a tag
  9. ;            that points to the file we came from is given
  10. ;            precedence over one in another file.
  11. ;                MAGIC mode can NOT be used to search for the
  12. ;            "regular expression" in the tagged file.  Aside from
  13. ;            the anchor characters "^" and "$", the rest of the
  14. ;            expression is the LITERAL string ctags found in the
  15. ;            file.  None of the special characters recognized in
  16. ;            MAGIC mode are escaped by the version of ctags in use.
  17. ;            Thus:
  18. ;            "^#define BCONSTAT 1    /* return status */$"
  19. ;
  20. ;            will fail, because "/*" matches "/", NOT the literal
  21. ;            "/*" actually in the line.
  22. ;
  23. ; 26 Apr 89 S.D. Maley        Isolate tagged_file & tagged_regex better.
  24. ;                add-mode exact or magic caused macro termination
  25. ;            under HPUX 5.2 .  !force them.
  26. ; 25 Apr 89 S.D. Maley        Handle more than whitespace in front of
  27. ;            the tag we want to look for.
  28. ; 22 Apr 89 S.D. Maley        Add %ctags_exact.  If user sets it TRUE
  29. ;            before invoking the to-tag macro, the search
  30. ;            will be case-sensitive.  Useful in C, but not
  31. ;            for most Fortran implementations.
  32. ; 19 Apr 89 S.D. Maley        Initial implementation.
  33. ;
  34. ;    Macros to make use of Unix-like ctags tag file.
  35. ; Assumes the existence of a file called "tags"
  36. ; (or whatever %tags_file is currently set to)
  37. ; which can be created using the "ctags" utility.
  38. ; If this file doesn't exist, the tags file is reported "Not found".
  39. ;    The format of each line of the tags file must be:
  40. ;
  41. ; tagword  filename  ?^pattern$?
  42. ;
  43. ; This is the normal output produced by the Unix utility "ctags".
  44. ;
  45. ;    For those unfamiliar with tagging, it is a form of hypertext.
  46. ; If you create a tags file for all your C source files you can locate
  47. ; the file and line where a given function is declared when you're in
  48. ; the editor, even if that function is declared in a different
  49. ; source file from the one you are editing.  Tagging will move you
  50. ; to that line in that file.
  51. ;
  52. ;    To use these macros, you can call "to-tag" directly as a command,
  53. ; or invoke it with the key combination M-<PgDn>.  Invoked directly,
  54. ; it will ask you to enter a tag.  Give the name of the function you
  55. ; are searching for (case sensitivity will depend on the current emacs
  56. ; setting).  If invoked with M-<PgDn>, the word where the cursor is
  57. ; positioned will be used as the tag to search for.
  58.  
  59. write-message "[Loading ctags macros]"
  60.  
  61. set %ctag ""
  62. set %ctag_ ""        ;-- for next-tag
  63. set %ctags_exact FALSE    ;-- set TRUE for case-sensitive searches
  64. set %ct_from_f ""    ;-- for find-next-tag
  65. set %tag_lvl 0
  66. set %tags_file "tags"    ;-- this can be reset from within Emacs
  67.  
  68. store-procedure find-next-tag
  69.    !force search-forward %ctag
  70.    !if ¬ $status
  71.       write-message &cat "Tag Not found: " %ctag
  72.       execute-procedure tag-out
  73.       !return
  74.    !endif
  75.  
  76.    ;-- Give precedence to a file that matches the one we came from
  77.    execute-procedure tagged-file-name
  78.    set %curline_ $curline
  79.    set %curcol_ $curcol
  80.    !while ¬ &sequ &upper %tagged_file %ct_from_f
  81.       !force search-forward %ctag
  82.       !if ¬ $status
  83.          goto-line %curline_
  84.          set $curcol %curcol_
  85.          !break
  86.       !endif
  87.       execute-procedure tagged-file-name
  88.    !endwhile    ;-- looking for a local tag
  89.    ;-- isolate the regular expression
  90.    3 forward-character    ;-- skip the leading whitespace & delimiters
  91.    set %tagged_regex #$cbufname
  92.    set %tagged_regex &left %tagged_regex &sub &len %tagged_regex 2
  93.  
  94.    ;-- get on down
  95.  
  96.    !force view-file %tagged_file
  97.    !if ¬ $status
  98.       execute-procedure tag-out
  99.       write-message &cat "File Not found: " %tagged_file
  100.       !return
  101.    !endif
  102.    execute-procedure set-bmodes
  103.    end-of-file    ;-- in case we've been this way before
  104.    ;-- search until we match at the beginning of a line
  105.    !while $status
  106.       !force search-reverse %tagged_regex
  107.       !if &less $curcol 1
  108.          !break
  109.       !endif
  110.    !endwhile
  111.    !if $status
  112.       write-message "<Esc><PgUp> to pop back"
  113.    !else
  114.       execute-procedure tag-out
  115.       write-message &cat "Tag Declaration Not found:~n" %tagged_regex
  116.       write-message "~ntags file should be re-generated with ctags"
  117.       !return
  118.    !endif
  119. !endm    ;-- find-next-tag
  120.  
  121.  
  122. store-procedure in-word
  123. !if &equ $curchar 95                ; underscore
  124.    set %in-word TRUE
  125. !else
  126. !if &and &less 64 $curchar &less $curchar 91    ; (A-Z)
  127.    set %in-word TRUE
  128. !else
  129. !if &and &less 96 $curchar &less $curchar 123    ; (a-z)
  130.    set %in-word TRUE
  131. !else
  132.    set %in-word FALSE
  133. !endif
  134. !endif
  135. !endif
  136. !endm
  137.  
  138. store-procedure next-tag
  139.    execute-procedure tag-dn-level
  140.    execute-procedure view-tags
  141.    !if ¬ %status
  142.       !return
  143.    !endif
  144.    set %ctag %ctag_
  145.    execute-procedure find-next-tag
  146.    set %ctag ""
  147. !endm
  148.  
  149. store-procedure set-bmodes
  150.    !if %ctags_exact    ; case-sensitive search
  151.       !force add-mode exact
  152.    !endif
  153.    !if &sequ %tags_buff $cbufname
  154.       !force add-mode magic    ; enable regular expression search
  155.    !else
  156.       !force delete-mode magic    ; dis-allow
  157.    !endif
  158. !endm
  159.  
  160. store-procedure tag-dn-level
  161.    ;-- push down a level
  162.    set %tag_lvl &add %tag_lvl 1
  163.    set &ind &cat "%tag_b" %tag_lvl $cbufname
  164.    set &ind &cat "%tag_c" %tag_lvl $curcol
  165.    set &ind &cat "%tag_l" %tag_lvl $curline
  166.    set &ind &cat "%tag_m" %tag_lvl $cmode
  167. !endm
  168.  
  169. store-procedure tagged-file-name
  170.    ;-- isolate the filename in the tags buffer (trailed by whitespace)
  171.    ;-- assuming we are positioned at the end of the tag
  172.    set %tagged_file ""
  173.    forward-character    ;-- skip the leading whitespace
  174.    !while &equ 0 &sindex " ~t" &chr $curchar
  175.       set %tagged_file &cat %tagged_file &chr $curchar
  176.       forward-character
  177.    !endwhile
  178. !endm
  179.  
  180. ; to-tag
  181. ;
  182. ; Looks in tags file for given tag, gets the filename and search
  183. ; pattern to use in locating the tag, opens the given file and
  184. ; searches for the pattern.  If the tag isn't found, reports an
  185. ; error.  There is no error checking in this macro for a valid
  186. ; function name (tag).
  187.  
  188. store-procedure to-tag
  189.    ;-- remember what file we came from for find-next-tag
  190.    set %ct_from_f &upper $cbufname
  191.    execute-procedure tag-dn-level    ;-- remember where we were
  192.    ;-- find out what we're looking for
  193.    !if &equ &len %ctag 0
  194.       set %prompt "tag: "
  195.       set %ctag @%prompt
  196.    !else
  197.       ;-- align cursor to beginning of tag
  198.       execute-procedure in-word
  199.       !while %in-word
  200.          !force backward-character    ;-- back up till we're not in a word
  201.      !if ¬ $status
  202.              !break    ;-- apparently clears $status
  203.          !endif
  204.          execute-procedure in-word
  205.       !endwhile ; in-word
  206.       !if ¬ &and &equ $curcol 0 &equ $curline 1 ;-- beginning-of-file
  207.          !force forward-character
  208.       !endif
  209.       ;-- isolate the tag
  210.       set %ctag_ "^"    ;-- tie to beginning-of-line
  211.       execute-procedure in-word
  212.       !while %in-word
  213.          set %ctag_ &cat %ctag_ &chr $curchar
  214.          !force forward-character
  215.          !if ¬ $status
  216.             !break ; a while
  217.          !endif
  218.          execute-procedure in-word
  219.       !endwhile
  220.    !endif
  221.    set %ctag %ctag_
  222.  
  223.    ;-- See if it's in the tags file
  224.  
  225.    execute-procedure view-tags
  226.    !if ¬ %status
  227.       !return
  228.    !endif
  229.    execute-procedure set-bmodes
  230.    beginning-of-file    ;-- in case we've been this way before
  231.    execute-procedure find-next-tag
  232.    set %ctag ""
  233. !endm
  234.  
  235. ; tag-out
  236. ;
  237. ; puts us back where we were before invoking tag
  238. ;
  239. store-procedure tag-out
  240.    !if &less 0 %tag_lvl        ;-- "&gre %tag_lvl 1" doesn't work
  241.       ;-- pop out a tag level
  242.  
  243.       select-buffer &ind &cat "%tag_b" %tag_lvl
  244.       set $cmode &ind &cat "%tag_m" %tag_lvl
  245.       goto-line &ind &cat "%tag_l" %tag_lvl
  246.       set $curcol &ind &cat "%tag_c" %tag_lvl
  247.       set %tag_lvl &sub %tag_lvl 1
  248.       update-screen
  249.    !endif
  250.    set %ctag ""
  251. !endm
  252.  
  253. store-procedure view-tags
  254.    !force view-file %tags_file
  255.    !if $status
  256.       set %tags_buff $cbufname
  257.       set %status TRUE
  258.    !else
  259.       execute-procedure tag-out
  260.       write-message &cat "File Not found: " %tags_file
  261.       set %status FALSE        ;-- we can NOT set $status
  262.    !endif
  263. !endm
  264.  
  265. store-procedure key-to-tag
  266.    set %ctag find
  267.    execute-procedure to-tag
  268. !endm
  269.  
  270. store-procedure key-tag-out
  271.    clear-message-line
  272.    execute-procedure tag-out
  273. !endm
  274.  
  275. macro-to-key key-to-tag  M-FNV    ;-- <Esc><PgDn>
  276. macro-to-key next-tag    M-FN>    ;-- <Esc><End> (could NOT: <Esc><Ctrl><PgDn>)
  277. macro-to-key key-tag-out M-FNZ    ;-- <Esc><PgUp>
  278.